package ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class BorrowSystemOp extends JFrame implements ActionListener {
	private JButton BorrowButton;
	private JButton ReturnButton;
	private JButton ReBorrowButton;
	private JButton returnbutton;
	public BorrowSystemOp() {
		JFrame jFrame = new JFrame("书籍借阅系统");
		//JPanel jpc = new JPanel();// 默认流式布局
		jFrame.setLayout(new BorderLayout());
		//jFrame.setSize(300, 200);
		JPanel jp1 = new JPanel(new GridLayout(2, 2, 10, 10));//设置新面板
		// 网格布局GridLayout(int rows, int columns, int hgap, int vgap)行数，列数，组件水平间距，垂直间距
		jp1.setBorder(BorderFactory.createTitledBorder("书籍借阅系统"));
		//this.setLayout(new FlowLayout());
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

		setTitle("书籍借阅系统界面");
		setSize(300, 200);
		setLocationRelativeTo(null);
		

		// 监听右上角的退出按钮
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent windowEvent) {
				System.exit(0);
			}
		});
		BorrowButton = new JButton("借阅书籍");
		ReturnButton = new JButton("归还书籍");
		ReBorrowButton = new JButton("续借书籍");
		
		jp1.add(BorrowButton);
		jp1.add(ReBorrowButton);
		jp1.add(ReturnButton);
		JPanel jp2 = new JPanel();
		returnbutton = new JButton("返回");
		returnbutton.addActionListener(this);
		jp2.add(returnbutton);
		add(jp2, BorderLayout.SOUTH);// 把按钮放到窗口最下方
		getContentPane().add(jp1,BorderLayout.CENTER);

		BorrowButton.addActionListener(this);
		ReturnButton.addActionListener(this);
		ReBorrowButton.addActionListener(this);

		this.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		BorrowSystem BorrowSystem = new BorrowSystem();
		if (e.getSource() == BorrowButton) {
			this.dispose();
			BorrowSystem.Borrowbutton();
		} else if (e.getSource() == ReturnButton) {
			this.dispose();
			BorrowSystem.Returnbutton();
		}else if (e.getSource() == ReBorrowButton) {
			this.dispose();
			BorrowSystem.Reborrowbutton();
		}  else if (e.getSource() == returnbutton) {
			this.dispose();
			new ReaderOp();
		}  
	}

}
